package com.steven.ourcontest.team.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.steven.ourcontest.R
import com.steven.ourcontest.team.bean.MatchInfo
import com.steven.ourcontest.team.bean.TeamMember

class MatchAdapter(private val context: Context, private val itemClickListener: ((id: Long, name: String) -> Unit)) :
    RecyclerView.Adapter<MatchViewHolder>() {
    val listData by lazy {
        ArrayList<MatchInfo>()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MatchViewHolder {
        val inflater =
            LayoutInflater.from(context).inflate(R.layout.item_match, parent, false)
        return MatchViewHolder(inflater)
    }

    override fun getItemCount(): Int {
        return listData.size
    }

    override fun onBindViewHolder(holder: MatchViewHolder, position: Int) {
        val itemData = listData[position]
        holder.apply {
            tv_name?.text = "竞赛：${itemData.name}"
            tv_belong?.text = "主办方——${itemData.belong}"
            itemView.setOnClickListener {
                itemClickListener.invoke(itemData.id, itemData.name)
            }
        }
    }
}

class MatchViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    val tv_name: TextView? = itemView.findViewById(R.id.tv_name)
    val tv_belong: TextView? = itemView.findViewById(R.id.tv_belong)
}
